package com.ruoyi.publish.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.service.ISysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.publish.mapper.BestServiceTableMapper;
import com.ruoyi.publish.domain.BestServiceTable;
import com.ruoyi.publish.service.IBestServiceTableService;
import org.springframework.util.CollectionUtils;

/**
 * 服务列表台账Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-03-12
 */
@Service
public class BestServiceTableServiceImpl implements IBestServiceTableService 
{
    @Autowired
    private BestServiceTableMapper bestServiceTableMapper;

    @Autowired
    private ISysDeptService deptService;

    /**
     * 查询服务列表台账
     * 
     * @param id 服务列表台账主键
     * @return 服务列表台账
     */
    @Override
    public BestServiceTable selectBestServiceTableById(Long id)
    {
        return bestServiceTableMapper.selectBestServiceTableById(id);
    }

    /**
     * 查询服务列表台账列表
     * 
     * @param bestServiceTable 服务列表台账
     * @return 服务列表台账
     */
    @Override
    public List<BestServiceTable> selectBestServiceTableList(BestServiceTable bestServiceTable) {
        List<BestServiceTable> bestServiceTables = bestServiceTableMapper.selectBestServiceTableList(bestServiceTable);
        List<SysDept> sysDepts = deptService.selectDeptList(new SysDept());
        for(BestServiceTable bestServiceTable1 : bestServiceTables){
            List<SysDept> collect = sysDepts.stream().filter(dept -> String.valueOf(dept.getDeptId()).equals(bestServiceTable1.getProjectCode())).collect(Collectors.toList());
            if(!CollectionUtils.isEmpty(collect)){
                bestServiceTable1.setProjectName(collect.get(0).getDeptName());
            }
        }
        return bestServiceTables;
    }

    /**
     * 新增服务列表台账
     * 
     * @param bestServiceTable 服务列表台账
     * @return 结果
     */
    @Override
    public int insertBestServiceTable(BestServiceTable bestServiceTable)
    {
        bestServiceTable.setCreateTime(DateUtils.getNowDate());
        return bestServiceTableMapper.insertBestServiceTable(bestServiceTable);
    }

    /**
     * 修改服务列表台账
     * 
     * @param bestServiceTable 服务列表台账
     * @return 结果
     */
    @Override
    public int updateBestServiceTable(BestServiceTable bestServiceTable)
    {
        bestServiceTable.setUpdateTime(DateUtils.getNowDate());
        return bestServiceTableMapper.updateBestServiceTable(bestServiceTable);
    }

    /**
     * 批量删除服务列表台账
     * 
     * @param ids 需要删除的服务列表台账主键
     * @return 结果
     */
    @Override
    public int deleteBestServiceTableByIds(Long[] ids)
    {
        return bestServiceTableMapper.deleteBestServiceTableByIds(ids);
    }

    /**
     * 删除服务列表台账信息
     * 
     * @param id 服务列表台账主键
     * @return 结果
     */
    @Override
    public int deleteBestServiceTableById(Long id)
    {
        return bestServiceTableMapper.deleteBestServiceTableById(id);
    }
}
